import {  View } from "@tarojs/components";
import React, { Component } from "react";

import {emotionAnalysis} from '../api/data-analysis';
import Echarts from "./Echarts";
export default class EmotionAnalysis extends Component{


 
  setChartOptions(chart) {
      
  emotionAnalysis("2020-10-10","2020-11-10").then(res=> {
    console.log(res);
    const data = res.data.data;
})
   let option = {

    tooltip: {

      trigger: 'item',

      formatter: "{a} \n {b}: {c} ({d}%)"

    },

    legend: {

      orient: 'vertical',

      top: 'middle',

      left: '60%',

      data: data.map(item => (item.name)),

      textStyle: {

        padding: [10, 0]

      }

    },

    series: [

      {

        name: '访问来源',

        type: 'pie',

        center: ['30%', '50%'],

        // radius: ['40%', '59%'],

        radius: '59%',

        // roseType:'radius',

        hoverOffset: 2,

        avoidLabelOverlap: false,

        label: {

          show: false,

          position: 'center'

        },

        emphasis: {

          label: {

            show: true,

            fontSize: '15',

            fontWeight: 'bold',

          }

        },

        itemStyle: {

          color: function (param) {

            return getColorByIndex(param.dataIndex);

          }

        },

        labelLine: {

          normal: {

            show: false

          }

        },


        data: data

      }

    ]

  };

  chart.setOption(option);
  }
  



    render() {
        return (
            <View>
                <Echarts setChartOptions={this.setChartOptions.bind(this)} />
            </View>
            )
        }    
}